<template>
	<view class="comments">
		<view class="section long" v-if="longComments.length">
			<view class="title">{{longComments.length}}条长评</view>
			<view class="comment-list">
				<CommentItem v-for="comment in longComments" :comment="comment" />
			</view>
		</view>
		<view class="section short" v-if="shortComments.length">
			<view class="title">{{shortComments.length}}条短评</view>
			<view class="comment-list">
				<CommentItem v-for="comment in shortComments" :comment="comment" />
			</view>
		</view>

		<view class="no-more">已显示全部评论</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shortComments: [],
				longComments: []
			};
		},
		onLoad(options) {
			// console.log(options);

			Promise.all([this.getLongComment(options.id), this.getShortComment(options.id)]).then(res => {
				uni.setNavigationBarTitle({
					title: `${this.longComments.length + this.shortComments.length}条评论`
				})
			})



		},
		methods: {
			getShortComment: function(storyid) {
				return new Promise((resolve, reject) => {
					uni.request({
						url: "https://apis.netstart.cn/zhihudaily/story/" + storyid +
							"/short-comments",
						success: (res) => {
							this.shortComments = [...res.data.comments]
							resolve(res)
						}
					})
				})

			},
			getLongComment: function(storyid) {
				return new Promise((resolve, reject) => {
					uni.request({
						url: "https://apis.netstart.cn/zhihudaily/story/" + storyid + "/long-comments",
						success: (res) => {
							this.longComments = [...res.data.comments]
							resolve(res)
						}
					})
				})

			}
		}
	}
</script>

<style lang="less">
	.comments {
		.section {
			.title {
				padding: 30rpx;
				font-weight: bold;
				font-size: 28rpx;
			}
		}

		.no-more {
			text-align: center;
			// height: 100rpx;
			// line-height: 100rpx;
			// background-color: #EEEEEE;
			font-size: 28rpx;
		}
	}
</style>
